package com.suray.wcs.service.system.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.suray.basic.wcs.path.core.Node;
import com.suray.basic.wcs.plc.utils.PlcTaskType;
import com.suray.basic.wcs.utils.Coord;
import com.suray.wcs.service.enums.TaskRgvProgress;
import com.suray.wcs.service.enums.TaskStatus;
import com.suray.wcs.service.enums.TaskType;
import com.suray.wcs.service.pojo.BaseEum;
import com.suray.wcs.service.pojo.Rgv;
import com.suray.wcs.service.system.entity.RgvDB;
import com.suray.wcs.service.system.entity.TaskDB;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * <p>
 * 服务类
 * </p>
 *
 * @author cooper
 * @since 2019-06-26
 */
public interface ITaskDBService extends IService<TaskDB> {

    void insertTask(List<TaskDB> taskDBS);

    void updateTaskProcessingRgv(Rgv rgv, TaskDB task);

    void updateTaskPreProcessingRgv(Rgv rgv, TaskDB task);

    /**
     * 预分配车辆更新为实际分配车辆,并更新任务状态
     * @param rgv
     * @param task
     * @param taskStatus
     * @param taskRgvProgress
     */
    void updateTaskProcessingRgvAndTaskRgvProgress(Rgv rgv, TaskDB task, TaskStatus taskStatus, TaskRgvProgress taskRgvProgress);

    boolean updateTaskRgvProgress(TaskDB task, TaskRgvProgress taskRgvProgress);

    TaskDB findFirstCanExecuteTask(Integer rgvNo);

    TaskDB findFirstCanExecuteTaskByTaskType(Integer rgvNo, TaskType taskType);

    TaskDB findFirstCanExecuteTaskForPreAssignAdjustOrAssigned(Integer rgvNo);

    /**
     * 查询分配给当前车的第一个任务
     *
     * @param rgvNo
     * @return
     */
    List<TaskDB> findCanExecuteTaskList(Integer rgvNo);

    /**
     * 查询已经分配车辆但是未完成的任务
     *
     * @param rgvNo 已经分配的车辆
     * @return
     */
    List<TaskDB> findCanReAssignTaskList(Integer rgvNo);

    List<TaskDB> findTaskListByRgvNo(Integer rgvNo);

    List<TaskDB> findTaskListByRgvNoAndZoneId(Integer rgvNo, Integer zoneId);

    boolean existUnFinishTask(Rgv rgv);

    List<TaskDB> findPreAndAssignTaskList(Integer rgvNo);

    TaskDB findLastPreAndAssignTaskList(Integer rgvNo);

    /**
     * 预分配但是未正式分车的任务
     *
     * @param rgvNo 预分配车辆
     * @return
     */
    List<TaskDB> findPreTaskList(Integer rgvNo);

    List<TaskDB> findCurrentFloorPreTaskList(Integer rgvNo, int floor);

    List<TaskDB> findPreTaskListByTaskType(Integer rgvNo, TaskType taskType);

    TaskDB findLastCanExecuteTask(Integer rgvNo);

    void updateTaskPlcProgressAndTaskStatus(TaskDB task, int taskProgress, TaskStatus taskStatus);

    void updateTaskPlcProgress(TaskDB task, int taskProgress);

    List<TaskDB> findAllNewTask();

    List<TaskDB> getPreProcessingRgvNoIsNull();

    List<TaskDB> getNoEndNodeTask();

    List<TaskDB> getRecoverAllNewTask();

    int deleteTask();

    int deleteTask(List<TaskDB> taskDBS);

    List<TaskDB> queryTaskInfo(TaskDB taskInfo);

    List<TaskDB> queryTasks(TaskDB taskDB);

    TaskDB queryTaskInfoById(Integer taskId);

    TaskDB queryTaskInfoByWMSId(String taskId);

    void updateSortCode(TaskDB task);

    boolean updateTaskStatus(TaskDB task, TaskStatus taskProgress);

    List<TaskDB> queryTaskForDays(Integer days);

    List<TaskDB> queryManualTaskForDays(Integer days);

    int updateTaskInfo(TaskDB taskdb);

    int updateTaskInfoAllowNull(TaskDB taskdb);

    List<BaseEum> queryTaskType();

    List<BaseEum> queryTaskStatus();

    List<BaseEum> queryTaskProgress();

    List<BaseEum> queryTaskRgvProgress();

    int findUnFinishOutTask();

    List<BaseEum> queryTaskStatusGroup();

    List<TaskDB> findAllUnFinishTask(TaskType taskType);

    boolean updateTaskById(TaskDB taskdb);

    List<TaskDB> getNotAssignmentTask();

    boolean updateTaskByIdAndType(TaskDB taskdb, Integer type);

    void runStation(Node start, Node end, PlcTaskType plcTaskType);

    int countByProcessingRgvNo(int rgvNo);

    List<TaskDB> getAllNoCommitToWmsTask();

    List<Integer> getRgvNoByCoord(Coord coord);

    void updateTaskProcessingRgvNoAndStatus(TaskDB unassignedTask, Integer processingRgvNo, TaskStatus wait, TaskRgvProgress assignedToRgv);

    List<TaskDB> findUnFinishTaskByDistrictAndRgvNOAndTaskType(int rgvNo, TaskType taskType);

    Set<Integer> getRgvNoByFloor(Integer floor, Integer zoneId);

    List<TaskDB> getUnFinishTaskListByFloor(int floor, Integer rgvNo);

    List<TaskDB> getUnAssignTaskListByFloor(int floor);

    List<TaskDB> getRgvUnToStartTask(RgvDB rgvdb);

    void updateTaskByTaskProgrammeGridId(TaskDB taskDB, String programmeName);

    void updateTaskPreProcessingRgvNo(TaskDB task, Integer preProcessingRgvNo, TaskRgvProgress taskRgvProgress);

    void updateTaskPreProcessingRgvNoAndProcessingRgvNo(TaskDB taskDB, Integer preProcessingRgvNo, Integer processingRgvNo, TaskRgvProgress taskRgvProgress);

    void updateTaskProcessingRgvNoAndPreProcessingRgvNo(TaskDB taskDB, Integer processingRgvNo, TaskRgvProgress taskRgvProgress, boolean flag);

    void updateTaskProcessingRgvNoAndPreProcessingRgvNo(TaskDB taskDB, Integer processingRgvNo, Integer preProcessingRgvNo, TaskRgvProgress taskRgvProgress);

    void updateTaskProcessingRgvNoAndPreProcessingRgvNoAndStatus(TaskDB unassignedTask, Integer rgvNo, Integer preProcessingRgvNo, TaskStatus wait, TaskRgvProgress assignedToRgv);

    List<TaskDB> findTasksByGroupId(Integer taskId, String groupId, Integer type);

    List<TaskDB> findTasksByGroupIdSecond(Integer taskId, String groupIdSecond);

    TaskDB findPreTaskByPreTaskId(Integer preTaskId);

    List<TaskDB> findTasksBySingleRgvFlag(String singleRgvFlag, Integer type);

    TaskDB findTaskByPreTaskId(Integer taskId);

    boolean updateTaskTips(TaskDB task, String tips);

    void deleteTaskForDays(Integer days);

    void deleteManualTaskForDays(Integer days);

    /*查询节点内是否有任务*/
    List<TaskDB> getTaskInRoad(List<Node> nodeList, Node forbidNode, Rgv rgv);

    List<TaskDB> findUnFinishOutOrTransferTaskByStartNodeStr(String startNodeStr, Integer taskId);

    List<TaskDB> findUnFinishOutOrTransferTaskByNodeStrList(Integer taskId, List<String> nodeStrList);

    List<TaskDB> getTaskInRoadLtTaskId(List<Node> doubleRoadNodeList, Integer taskId, Integer priorityCode);

    TaskDB getTaskDBById(Integer taSKId);

    Set<Integer> queryTaskByLimitRgvFlag(Integer nodeId, Integer type);

    int updateTaskEndNodeStr(TaskDB taskdb, Node endNode);

    public int countExecTask(TaskType taskType);

    public int countCancelTask(TaskType taskType);

    public int countFinishTask(TaskType taskType);

    public int countErrorTask(TaskType taskType);

    public int countWaitForExecTask(TaskType taskType);

    List<TaskDB> findUnFinishAvoidTaskByEndNodeStrAndTaskType(String endNodeStr, Integer rgvNo, TaskType taskType);

    List<TaskDB> findPreProcessingTasksByRgvNo(Integer rgvNo);

    List<TaskDB> queryErrorTasksByRgvNo(Integer rgvNo);

    List<Map<String, Object>> getGraphData(TaskDB taskDB);

    List<TaskDB> findTasksBySingleRgvFlagAndRgvNo(TaskDB preTaskDB, Integer rgvNo);

    int countTaskByEndStr(String endNodeStr);

    List<TaskDB> findPreProcessingTasksByRgvNoAndTaskType(Integer rgvNo, TaskType parseTaskType);

    List<TaskDB> findUnFinishInOrTransferByEndNode(Node node);
}
